package com.example.smart.util;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

abstract public class SecurityUtils {
    public static UserDetails getLogin() {
        Object object = getAuthentication().getPrincipal();
        if (object instanceof UserDetails) {
            return (UserDetails) object;
        }
        return null;
    }

    public static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    public static void setAuthentication(Authentication authentication) {
        SecurityContextHolder.getContext().setAuthentication(authentication);
    }
}
